package com.example.chao.myphotosearch.adapters;

import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.example.chao.myphotosearch.adapters.holders.BaseViewHolder;
import com.example.chao.myphotosearch.adapters.holders.JoyImageViewHolder;
import com.example.chao.myphotosearch.bean.ImageJoy;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by chao on 2016/4/27.
 */
public class JoyAdapter extends RecyclerView.Adapter<BaseViewHolder<ImageJoy>> {
    private List<ImageJoy> joys;

    @Inject
    public JoyAdapter() {
        this.joys = new ArrayList<>();
    }

    public void setJoys(List<ImageJoy> joys) {
        if (joys != null) {
            this.joys = joys;
            notifyDataSetChanged();
        }
    }

    @Override
    public BaseViewHolder<ImageJoy> onCreateViewHolder(ViewGroup parent, int viewType) {
        return new JoyImageViewHolder(parent);
    }

    @Override
    public void onBindViewHolder(BaseViewHolder<ImageJoy> holder, int position) {
        holder.setData(joys.get(position));
    }

    @Override
    public int getItemCount() {
        return joys.size();
    }
}
